package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.CodingRules;
import com.example.demo.service.CodingRulesService;
import com.example.demo.mapper.CodingRulesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【coding_rules】的数据库操作Service实现
* @createDate 2024-11-27 17:02:36
*/
@Service
public class CodingRulesServiceImpl extends ServiceImpl<CodingRulesMapper, CodingRules>
    implements CodingRulesService{
    @Autowired
    CodingRulesMapper codingRulesMapper;
    @Override
    public List<CodingRules> select(String userId, String appId, String trainingId) {
        QueryWrapper<CodingRules> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("appId",appId);
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.orderByDesc("id");
        return codingRulesMapper.selectList(queryWrapper);
    }

    @Override
    public Integer deleteById(Integer id) {
        return codingRulesMapper.deleteById(id);
    }

    @Override
    public Integer deleteByInfo(String userId, String appId, String trainingId) {
        QueryWrapper<CodingRules> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        if(appId!=null){
            queryWrapper.eq("appId",appId);
        }
        queryWrapper.eq("trainingId",trainingId);
        queryWrapper.orderByDesc("id");
        return codingRulesMapper.delete(queryWrapper);
    }
}




